<?php

class ContatoController extends Site_Controller_Action
{

    public function init()
    {
        $this->titulo = 'Contato - '.$this->titulo;
    }

    public function indexAction()
    {
        
        $this->view->headLink()->prependStylesheet($this->_urlbase.'/public/media/js/jquery-ui-1.10.2.custom/css/custom-theme/jquery-ui-1.10.2.custom.css'); 
        $this->view->headScript()->appendFile($this->_urlbase.'/public/media/js/jquery-ui-1.10.2.custom/js/jquery-1.9.1.min.js');
        $this->view->headScript()->appendFile($this->_urlbase.'/public/media/js/jquery-ui-1.10.2.custom/js/jquery-ui-1.10.2.custom.min.js');
        
        $this->view->headScript()->appendFile($this->_urlbase.'/public/media/js/validation/dist/jquery.validate.min.js');
        $this->view->headScript()->appendFile($this->_urlbase.'/public/media/js/view/contato.js');
        
        $this->view->submenu_page = TRUE;
        
        $form = new Application_Form_Contato();
        
        $this->view->form = $form;
        if ($this->getRequest()->isPost()) {
            try {
                $formData = $this->getRequest()->getPost();
                if($form->isValid($formData)) {

                    Zend_Loader::loadClass('envioemail','library');
                    $arr['nome'] = $form->getValue('nome');
                    $arr['email'] = $form->getValue('email');
                    $arr['assunto'] = $form->getValue('assunto');
                    $arr['mensagem'] = $form->getValue('mensagem');
                    $arr['urlbase']  = $this->_urlbase;
                    $ok = envioemail::formularioContato($arr);
                    
                    if($ok){
                        $form->reset();
                        $this->view->retorno = "<script>alert('Mensagem enviada com sucesso!');</script>";
                    }
                }
            } catch (Exception $exc) {
                //echo 'error: '.$exc->getMessage();
            }
        }
        
    }

}

